﻿using UnityEditor;
using UnityEngine;


namespace UIFramwork
{
    [CanEditMultipleObjects]
    [CustomEditor(typeof(UIBase), true)]
    public class UIBaseEditor : Editor
    {
        private UIBase m_UI;

        public void OnEnable()
        {
            m_UI = target as UIBase;
        }


        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("索引引用对象"))
            {
                m_UI.InitComponent();
                EditorUtility.SetDirty(m_UI);
            }

            EditorGUILayout.BeginHorizontal();
            {
                bool isHideLast = GUILayout.Toggle(m_UI.UseCloseOld, "关旧", "button");
                if (m_UI.UseCloseOld != isHideLast)
                {
                    m_UI.UseCloseOld = isHideLast;
                    EditorUtility.SetDirty(m_UI);
                }

                bool isAllowClosed = GUILayout.Toggle(m_UI.CanBeClosed, "可关", "button");
                if (m_UI.CanBeClosed != isAllowClosed)
                {
                    m_UI.CanBeClosed = isAllowClosed;
                    EditorUtility.SetDirty(m_UI);
                }

                bool isBeRecord = GUILayout.Toggle(m_UI.CanBeRecord, "记录", "button");
                if (m_UI.CanBeRecord != isBeRecord)
                {
                    m_UI.CanBeRecord = isBeRecord;
                    EditorUtility.SetDirty(m_UI);
                }
            }
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            {
                bool isBCollider = GUILayout.Toggle(m_UI.UseAreaQuit, "阻挡", "button");
                if (m_UI.UseAreaQuit != isBCollider)
                {
                    m_UI.UseAreaQuit = isBCollider;
                    EditorUtility.SetDirty(m_UI);
                }


                bool isBlackMask = GUILayout.Toggle(m_UI.UseMask, "蒙版", "button");
                if (m_UI.UseMask != isBlackMask)
                {
                    m_UI.UseMask = isBlackMask;
                    EditorUtility.SetDirty(m_UI);
                }

                bool isUseQuard = GUILayout.Toggle(m_UI.UseQuardRato, "四周型", "button");
                if (m_UI.UseQuardRato != isUseQuard)
                {
                    m_UI.UseQuardRato = isUseQuard;
                    EditorUtility.SetDirty(m_UI);
                }

                bool isBeReused = GUILayout.Toggle(m_UI.UseAsSingle, "复用", "button");
                if (m_UI.UseAsSingle != isBeReused)
                {
                    m_UI.UseAsSingle = isBeReused;
                    EditorUtility.SetDirty(m_UI);
                }
            }
            EditorGUILayout.EndHorizontal();


            base.OnInspectorGUI();
        }
    }
}
